Skip to content

fix: only retry urldecoded password when decoding changes it (LDAP badPwdCount double-increment) - #62474

Open
mvanhorn wants to merge 1 commit into
nextcloud:masterfrom
mvanhorn:fix/33657-ldap-double-badpwdcount
Open

fix: only retry urldecoded password when decoding changes it (LDAP badPwdCount double-increment)#62474
mvanhorn wants to merge 1 commit into
nextcloud:masterfrom
mvanhorn:fix/33657-ldap-double-badpwdcount

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

When a wrong password is entered for an LDAP or Active Directory user, the directory's failed-login counter is increased by two instead of one. Administrators who lock accounts after three failed attempts therefore find users locked out after only two mistakes, which causes avoidable lockouts and support load.

The cause is in the password check inside the user manager. After the first authentication attempt with the plain password fails, the method decodes the password and then tries every backend a second time. That second pass exists so that non-ASCII passwords sent over HTTP basic auth, which arrive percent-encoded, can still be verified. The problem is that the second pass ran unconditionally, even when the password contained nothing to decode, so an ordinary wrong password produced two identical authentication attempts and two directory binds for a single login.

This change performs the second attempt only when decoding actually changes the password. When decoding leaves the password unchanged, the method now returns right after the first attempt, so one wrong password results in exactly one directory bind and one counter increment. The compatibility path for genuinely percent-encoded passwords is preserved: when decoding does change the value, the second attempt still runs against the decoded password.

Two unit tests were added. The first checks that a wrong password with nothing to decode reaches the backend exactly once. The second checks that a percent-encoded password still triggers a second attempt with the decoded value and authenticates when the decoded form is accepted.

Fixes #33657

TODO

Nothing outstanding. The change is self-contained and covered by the added tests.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI was used for assistance.

…dPwdCount double-increment)

Fixes nextcloud#33657

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn
mvanhorn requested a review from a team as a code owner July 24, 2026 09:20
@mvanhorn
mvanhorn requested review from Altahrim, leftybournes, provokateurin and salmart-dev and removed request for a team July 24, 2026 09:20
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: a wrong password will trigger badPwdCount twice in ldap

1 participant